﻿using HDJ.Framework.Core;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;

namespace HDJ.Framework.Core.Editor
{
    public class TableConfigEditorWindow : EditorWindow
    {


        [MenuItem("Tool/Table配置文件", priority = 1101)]
        static void OpenWindow()
        {
            TableConfigEditorWindow ce = EditorWindow.GetWindow<TableConfigEditorWindow>();
            ce.wantsMouseMove = true;
            ce.autoRepaintOnSceneChange = true;

        }
        TableDataEditor tableData;
        private void OnEnable()
        {
            if (tableData == null)
            {
                tableData = new TableDataEditor();
                tableData.Init(this, TableDefine.SaveConfigFilePath);
                tableData.OnLoadTableFile = OnLoadTableFile;
                tableData.OnSaveTableData = OnSaveTableData;
                tableData.OnClearModuleCache = () =>
                {
                    TableManager.Clear();
                };
            }
        }
        private TableData OnLoadTableFile(string flieName)
        {
            Debug.Log("OnLoadTableFile:" + fileName);
            return TableManager.GetTableData(fileName);
        }
        private void OnSaveTableData(string fileName, TableData data)
        {
            string text = TableUtils.TableData2Text(data);
            FileUtils.CreateTextFile(TableDefine.SaveConfigFilePath + fileName + ".txt", text);
        }

        private string fileName = "";
        private void OnGUI()
        {
            fileName = tableData.OnGUI(fileName);
        }

        private void OnDestroy()
        {
            tableData.OnDestroy();
        }

    }
}


